/**
 * 食药公用js
 *
 * */
define([
    'base',
    'artTemplate',
    'msgTool',
    'bootstrapDialog',
    'laydate',
    'bootstrapTable',
    'css!global/plugins/viewer/viewer.min.css',
    'plugins/fileInput/fileinput.min',
    'css!global/plugins/fileInput/fileinput.min.css'
], function (base, template, msgTool, BootstrapDialog, laydate) {
    //默认加载基础库
    base();


    return {
        index: function () {
            var myTable = $('#dataList');
            var fileListUrl = '/implementation/view/api';
            var tableRefresh = function () {
                myTable.bootstrapTable('refresh', {url: fileListUrl})
            };
            //table按需刷新动作
            var doAction = function () {
                myTable.bootstrapTable('refresh', {url: fileListUrl})
            };

            //table当前行的响应事件
            window.operateEvents = {
                'click .update': function (e, value, row) {
                    window.location.href = "../update/" + row.unid;
                },
                'click .info': function (e, value, row) {
                    window.location.href = "../view/" + row.unid;
                },
                'click .status': function (e, value, row) {
                    $.baseUtils.oneStatus({
                        row: row,
                        tableName: myTable,
                        nameText: '实施清单',
                        nameValue: row.serviceName,
                        url: '../status/action'
                    })
                },

                'click .delete': function (e, value, row) {
                    row.id = row.unid;
                    $.baseUtils.oneDelete({
                        row: row,
                        tableName: myTable,
                        nameText: '实施清单',
                        nameValue: row.serviceName,
                        url: '../delete/action'
                    });
                }
            };


            //table表格
            myTable.bootstrapTable({
                url: fileListUrl, // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                fixedColumns: true,//自动修复
                queryParams: queryParams,//搜索附加参数
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                mobileResponsive: "true", //手机模式自适应宽度（自动变成卡片模式）
                columns: [
                    {
                        field: 'serviceCode',
                        title: '事项编码',
                        width: '15%'
                    }, {
                        field: 'serviceName',
                        title: '事项名称',
                        width: '35%'
                    },
                    {
                        field: 'deptName',
                        title: '实施主体',
                        align: 'center',
                        width: '10%'
                    },
                    {
                        field: 'createTime',
                        title: '创建时间',
                        align: 'center',
                        width: '15%'
                    },
                    {
                        field: 'status',
                        title: '状态',
                        width: '5%',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var result = "";
                            switch (value) {
                                case "N":
                                    result = "<span class=\"label label-danger\"><i class=\"fa fa-lock\" aria-hidden=\"false\"></i>&nbsp;禁用</span>";
                                    break;
                                case "Y":
                                    result = "<span class=\"label label-primary\"><i class=\"fa fa-unlock\" aria-hidden=\"true\"></i>&nbsp;启用</span>";
                                    break;
                                default:
                                    break;
                            }
                            return result;
                        }
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        width: '20%',
                        formatter: operateFormatter,
                        events: operateEvents
                    }
                ]
            });

            //搜索刷新
            $('#search-btn').on('click', function () {
                tableRefresh();
            });


            //刷新
            $(".toolbar-refresh").on('click', function () {
                tableRefresh();
            });

            //搜索参数传递
            function queryParams(params) {
                params.search = $("#search").val();
             //   params.deptName = $("#deptName").val();
                return {
                    limit: params.limit,
                    offset: params.offset,
                 //   deptName: params.deptName,
                    search: params.search
                };
            }

            //回显
            function responseHandler(res) {
                return res.rows;
            }

        },



        /**
         * 保存
         */
        save: function (isDisable) {

            /**
             * 申请方式
             */
            var applyTypeCode0 = template('applyTypeCode0', {});
            var applyTypeCode1 = template('applyTypeCode1', {});
            var applyTypeCode2 = template('applyTypeCode2', {});
            var applyTypeCode3 = template('applyTypeCode3', {});
            var applyTypeCode4 = template('applyTypeCode4', {});
            $("#applyType0").html("");
            $("#applyType1").html(applyTypeCode1);
            $("#applyType2").html("");
            $("#applyType3").html("");
            $("#applyType4").html("");
            $("#applyTypeTips").html("");

            //打开页面执行
            var showApplyType = $('input:radio[name="applyType"]:checked').val();
            if (showApplyType != null) {
                executeApplyType(showApplyType);
            }

            //点击按钮执行
            $("input:radio[name='applyType']").on("click", function () {
                var applyType = $('input:radio[name="applyType"]:checked').val();
                executeApplyType(applyType);
            });

            //执行内容展示切换
            function executeApplyType(applyType) {
                switch (applyType) {
                    case "in01":
                        $("#applyType0").html("");
                        $("#applyType1").html(applyTypeCode1);
                        $("#applyType2").html("");
                        $("#applyType3").html("");
                        $("#applyType4").html("");
                        break;
                    case "in02":
                        $("#applyType0").html(applyTypeCode0);
                        $("#applyType1").html(applyTypeCode1);
                        $("#applyType2").html("");
                        $("#applyType3").html("");
                        $("#applyType4").html("");
                        break;
                    case "in04":
                        $("#applyType0").html(applyTypeCode0);
                        $("#applyType1").html(applyTypeCode1);
                        $("#applyType2").html(applyTypeCode2);
                        $("#applyType3").html(applyTypeCode3);
                        $("#applyType4").html(applyTypeCode4);
                        break;
                    case "in05":
                        $("#applyType0").html(applyTypeCode0);
                        $("#applyType1").html(applyTypeCode1);
                        $("#applyType2").html(applyTypeCode2);
                        $("#applyType3").html(applyTypeCode3);
                        $("#applyType4").html(applyTypeCode4);
                        break;
                }
            }

            /**
             * 上传（办理结果 - 结果样本）
             */
            $.baseUtils.uploader({
                filesType: 0,
                showCaption: false,
                browseLabel: "选择样本图...",
                uploadLabel: "上传",
                cssName: "#addfileUpload",
                browseClass: 'btn btn-primary',
                uploadClass: 'btn btn-info',
                errorCssName: "#error-message",
                fileExtensions: ['jpg', 'png', 'gif', 'jpeg']
                //layoutTemplates: {actionUpload: ''}
            }).on("fileuploaded", function (event, data) {
                if (data.response !== null && data.response.status) {
                    //提交数据
                    $("#resultExample").val(data.response.url);
                    //展示数据
                    $("#resultExampleUrl").val(data.response.domain + data.response.url);
                    $("#fileShow").find("img").attr("src", data.response.domain + data.response.url);
                } else {
                    msgTool.error(data.response.message, "信息提示");
                }
            });

            /**
             * 流程图
             */
            $.baseUtils.uploader({
                filesType: 0,
                showCaption: false,
                browseLabel: "选择外部流程图...",
                uploadLabel: "上传",
                cssName: "#powerFlowUpload",
                browseClass: 'btn btn-primary',
                uploadClass: 'btn btn-info',
                errorCssName: "#flow-error-message",
                fileExtensions: ['jpg', 'png', 'gif', 'jpeg']
                //layoutTemplates: {actionUpload: ''}
            }).on("fileuploaded", function (event, data) {
                if (data.response !== null && data.response.status) {
                    //提交数据
                    $("#flowContent").val(data.response.url);
                    //展示数据
                    $("#flowContentUrl").val(data.response.domain + data.response.url);
                    $("#flowShow").find("img").attr("src", data.response.domain + data.response.url);
                } else {
                    msgTool.error(data.response.message, "信息提示");
                }
            });

            if (isDisable) {
                //禁止表单
                $("#basicForm :text").attr("disabled",true);
                $("#basicForm input[type='number']").attr("disabled",true);
                $("#basicForm textarea").attr("disabled",true);
                $("#basicForm select").attr("disabled",true);
                $("#basicForm :radio").attr("disabled",true);
                $("#basicForm :checkbox").attr("disabled",true);
                $("#addfileUpload").remove();
                $("#resultExampleUrl").remove();
                $("#resultExampleUrl").remove();
                $("#result-error-message").remove();
                $("#powerFlowUpload").remove();
                $("#flowContentUrl").remove();
                $("#flow-error-message").remove();
                $(".panel-footer").remove();
            }

            /**
             * 保存
             */
            $("#doSubmit").on('click', function () {
                    var form = $("form[name='basicForm']");
                    //var dataFormStatus = form.validate().form();
                    if (true) {
                        $.ajax({
                            url: "/implementation/save/action",
                            type: 'POST',
                            data: form.serialize(),
                            beforeSend: function () {
                                $("#doSubmit").text('提交中...');
                                $("#doSubmit").attr('disabled', 'disabled');
                            },
                            success: function (data) {
                                if (data.success) {
                                    window.location.href = "/implementation/view/time/" + data.msg;
                                } else {
                                    msgTool.error(data.msg);
                                }
                            },
                            error: function () {
                                msgTool.error("操作失败，请刷新当前页面后重试！");
                            },
                            complete: function () {
                                $("#doSubmit").text("保存");
                                $("#doSubmit").removeAttr('disabled');
                            }
                        });

                    }
                }
            );

            /**
             * 预约时间
             */
            laydate.render({elem: '#amStartTime', type: 'time', format: 'HH:mm'});
            laydate.render({elem: '#amEndTime', type: 'time', format: 'HH:mm'});
            laydate.render({elem: '#pmStartTime', type: 'time', format: 'HH:mm'});
            laydate.render({elem: '#pmEndTime', type: 'time', format: 'HH:mm'});

        },

        /**
         * 时限配置
         */
        time: function (serviceId) {
            var timeTable = $('#timeDataList');
            var fileListUrl = '/implementTime/view/api/' + serviceId;
            var tableRefresh = function () {
                timeTable.bootstrapTable('refresh', {url: fileListUrl})
            };

            //table当前行的响应事件
            window.operateEvents = {
                'click .update': function (e, value, row) {
                    winModal("编辑", row);
                },
                'click .delete': function (e, value, row) {
                    $.baseUtils.oneDelete({
                        row: row,
                        tableName: timeTable,
                        nameText: '环节名称',
                        nameValue: row.sname,
                        url: '/implementTime/delete/action'
                    });
                }
            };


            //table表格
            timeTable.bootstrapTable({
                url: fileListUrl, // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                pageSize: 50,
                fixedColumns: true,//自动修复
                queryParams: function () {
                },//搜索附加参数
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                columns: [
                    {
                        field: 'sortid',
                        title: '序号',
                        align: 'center',
                        width: '5%'
                    }, {
                        field: 'sname',
                        title: '环节名称',
                        width: '50%'
                    },
                    {
                        field: 'sday',
                        title: '环节时限（工作日）',
                        align: 'center',
                        width: '10%'
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        width: '30%',
                        formatter: function operateFormatter() {
                            var tempCode = "";
                            tempCode += '<button type="button" class="update btn btn-white">&nbsp;<i class="fa fa-edit"></i>&nbsp;修改&nbsp;</button>';
                            tempCode += '<button type="button" class="delete btn btn-white">&nbsp;<i class="fa fa-trash"></i>&nbsp;删除&nbsp;</button>';
                            return '<div class="btn-group btn-group-xs">' + tempCode + '</div>';
                        },
                        events: operateEvents
                    }
                ]
            });

            //工具栏 - 新增
            $('.toolbar-save').on('click', function () {
                winModal("特殊环节配置", null);
            });

            /**
             * table公共方法
             */
            //工具栏 - 刷新
            $(".toolbar-refresh").on('click', function () {
                tableRefresh();
            });

            //回显
            function responseHandler(res) {
                return res.rows;
            }


            /**
             * 模态框
             * @param title
             * @param row
             */
            function winModal(title, row) {
                BootstrapDialog.show({
                    type: BootstrapDialog.TYPE_DEFAULT,
                    tabindex: null,//解决select2搜索框失去焦点的问题
                    title: title,
                    closable: true,	//关闭箭头启动
                    closeByBackdrop: false,	//点击空白不消失
                    closeByKeyboard: true,//ESC取消禁用
                    message: $('<div></div>').load('/implementTime/save/form.html'),
                    data: {
                        'row': row
                    },
                    buttons: [{
                        label: '取消',
                        cssClass: 'btn-white cancel',
                        icon: 'fa fa-times',
                        action: function (dialog) {
                            dialog.close();
                        }
                    }, {
                        label: '提交' + title,
                        //hotkey: 13,//回车提交
                        cssClass: 'btn-primary',
                        icon: 'fa fa-check',
                        action: function (dialog) {
                            //返回验证结果
                            var flag = $("#winModal").validate().form();
                            if (flag) {
                                $.baseUtils.ajax({
                                    dialog: dialog,
                                    url: '/implementTime/save/action',
                                    data: $("#winModal").serialize(),
                                    text: "保存",
                                    isTable: true,
                                    tableName: '#timeDataList',
                                    isDialog: true
                                })
                            }
                        }
                    }],
                    onshown: function () {
                        $('#serviceId').val(serviceId);
                        if (row != null) {
                            $('#uuid').val(row.uuid);
                            $('#sname').val(row.sname);
                            $('#sday').val(row.sday);
                            $('#ihjsx').val(row.ihjsx);
                            $('#sconent').val(row.sconent);
                            $('#sremark').val(row.sremark);
                            $('#sortid').val(row.sortid);
                        }
                    }
                });
            }


        },

        /**
         * 材料文件
         */
        files: function (serviceId) {
            var filesTable = $('#filesDataList');
            var filesDomain = filesTable.data("files-domain");
            var fileListUrl = '/implementFiles/view/api/' + serviceId;
            var tableRefresh = function () {
                filesTable.bootstrapTable('refresh', {url: fileListUrl})
            };

            //table当前行的响应事件
            window.operateEvents = {
                'click .update': function (e, value, row) {
                    winModal("编辑", row);
                },
                'click .status': function (e, value, row) {
                    $.baseUtils.oneStatus({
                        row: row,
                        tableName: filesTable,
                        nameText: '申请材料',
                        nameValue: row.name,
                        url: '/implementFiles/status/action'
                    })
                },
                'click .delete': function (e, value, row) {
                    $.baseUtils.oneDelete({
                        row: row,
                        tableName: filesTable,
                        nameText: '申请材料',
                        nameValue: row.name,
                        url: '/implementFiles/delete/action'
                    });
                }
            };


            //table表格
            filesTable.bootstrapTable({
                url: fileListUrl, // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                pageSize: 50,
                fixedColumns: true,//自动修复
                queryParams: function () {
                },//搜索附加参数
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                columns: [
                    {
                        field: 'sortid',
                        title: '排序',
                        width: '10%',
                        align: 'center'
                    }, {
                        field: 'name',
                        title: '文件名称',
                        width: '40%'
                    },
                    {
                        field: 'createTime',
                        title: '上传时间',
                        align: 'center',
                        width: '10%'
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '10%',
                        align: 'center',
                        formatter: function (value) {
                            var result = "";
                            switch (value) {
                                case "N":
                                    result = "<span class=\"label label-danger\">&nbsp;禁用</span>";
                                    break;
                                case "Y":
                                    result = "<span class=\"label label-primary\">&nbsp;启用</span>";
                                    break;
                            }
                            return result;
                        }
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        width: '20%',
                        formatter: function operateFormatter(value, row) {
                            var tempCode = "";
                            if (row.status === "Y") {
                                tempCode += '<button type="button" class="status btn btn-default btn-white"><i class="fa fa-toggle-off"></i>&nbsp;禁用&nbsp;</button>';
                            } else {
                                tempCode += '<button type="button" class="status btn btn-default btn-white"><i class="fa fa-toggle-on"></i>&nbsp;启用&nbsp;</button>';
                            }
                            tempCode += '<button type="button" class="update btn btn-white">&nbsp;<i class="fa fa-edit"></i>&nbsp;修改&nbsp;</button>';
                            tempCode += '<button type="button" class="delete btn btn-white">&nbsp;<i class="fa fa-trash"></i>&nbsp;删除&nbsp;</button>';
                            return '<div class="btn-group btn-group-xs">' + tempCode + '</div>';
                        },
                        events: operateEvents
                    }
                ]
            });

            //工具栏 - 新增
            $('.toolbar-save').on('click', function () {
                winModal("新增", null);
            });

            //工具栏 - 刷新
            $(".toolbar-refresh").on('click', function () {
                tableRefresh();
            });

            //回显
            function responseHandler(res) {
                return res.rows;
            }

            //模态框
            function winModal(title, row) {
                BootstrapDialog.show({
                    type: BootstrapDialog.TYPE_DEFAULT,
                    size: BootstrapDialog.SIZE_WIDE,
                    tabindex: null,//解决select2搜索框失去焦点的问题
                    title: title,
                    closable: true,	//关闭箭头启动
                    closeByBackdrop: false,	//点击空白不消失
                    closeByKeyboard: true,//ESC取消禁用
                    message: $('<div></div>').load('/implementFiles/save/form.html'),
                    data: {
                        'row': row
                    },
                    buttons: [{
                        label: '取消',
                        cssClass: 'btn-white cancel',
                        icon: 'fa fa-times',
                        action: function (dialog) {
                            dialog.close();
                        }
                    }, {
                        label: '提交' + title,
                        //hotkey: 13,//回车提交
                        cssClass: 'btn-primary',
                        icon: 'fa fa-check',
                        action: function (dialog) {
                            //返回验证结果
                            var flag = $("#winModal").validate().form();
                            if (flag) {
                                $.baseUtils.ajax({
                                    dialog: dialog,
                                    url: '/implementFiles/save/action',
                                    data: $("#winModal").serialize(),
                                    text: "保存",
                                    isTable: true,
                                    tableName: '#filesDataList',
                                    isDialog: true
                                })
                            }
                        }
                    }],
                    onshown: function () {

                        /**
                         * 上传图片
                         */
                        $.baseUtils.uploader({
                            filesType: 1,
                            showCaption: false,
                            browseLabel: "选择材料文件",
                            uploadLabel: "上传",
                            cssName: "#filesUploader",
                            errorCssName: "#error-message",
                            fileExtensions: ['jpg', 'png', 'gif', 'jpeg', 'txt', 'zip', 'rar', '7z', 'doc', 'docx', 'xlsx', 'xls', 'pdf', 'ppt'],
                        }).on("fileuploaded", function (event, data) {
                            if (data.response !== null && data.response.status) {
                                $("#fileUrl").val(data.response.url);
                                $("#fileShow").html(
                                    "<div class='mt15'>" +
                                    "<a href=\"" + data.response.domain + data.response.url + "\" target=\"_blank\"><i class='fa fa-file'></i>&nbsp;" + data.response.originalName + "</a>" +
                                    "</div>");
                            } else {
                                msgTool.error(data.response.message, "信息提示");
                            }
                        });

                        $('#serviceId').val(serviceId);
                        if (row != null) {
                            $('#uuid').val(row.uuid);
                            $('#classifyName').val(row.classifyName);
                            $('#classifyId').val(row.classifyId);
                            $('#name').val(row.name);
                            $('#code').val(row.code);
                            $('#format').val(row.format);
                            $('#importLevel').val(row.importLevel);
                            $('#getTypes').val(row.getTypes);
                            $('#srcWay').val(row.srcWay);
                            $('#submitRequire').val(row.submitRequire);
                            $('#srcNum').val(row.srcNum);
                            $('#copyNum').val(row.copyNum);
                            $('#memo').val(row.memo);
                            $('#type').val(row.type);
                            $('#isNeedElec').val(row.isNeedElec);
                            $('#acceptRequire').val(row.acceptRequire);
                            $('#fileUrl').val(row.fileUrl);
                            $('input[name=status][value=' + row.status + ']').attr('checked', true);
                            $('#sortid').val(row.sortid);
                            $("#fileShow").html(
                                "<div class='mt15'>" +
                                "<a href=\"" + filesDomain + row.fileUrl + "\" target=\"_blank\"> <i class='fa fa-file'></i>&nbsp;" + row.fileUrl + "</a>" +
                                "</div>");
                        }
                    }
                });
            }
        },

        /**
         * 常见问题
         */
        answer: function (serviceId) {

            var anwserTable = $('#anwserDataList');
            var fileListUrl = '/implementAnswer/view/api/' + serviceId;
            var tableRefresh = function () {
                anwserTable.bootstrapTable('refresh', {url: fileListUrl})
            };

            //table当前行的响应事件
            window.operateEvents = {
                'click .update': function (e, value, row) {
                    winModal("编辑", row);
                },
                'click .status': function (e, value, row) {
                    $.baseUtils.oneStatus({
                        row: row,
                        tableName: anwserTable,
                        nameText: '常见问题',
                        nameValue: row.title,
                        url: '/implementAnswer/status/action'
                    })
                },
                'click .delete': function (e, value, row) {
                    $.baseUtils.oneDelete({
                        row: row,
                        tableName: anwserTable,
                        nameText: '常见问题',
                        nameValue: row.title,
                        url: '/implementAnswer/delete/action'
                    });
                }
            };


            //table表格
            anwserTable.bootstrapTable({
                url: fileListUrl, // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                pageSize: 50,
                fixedColumns: true,//自动修复
                queryParams: function () {
                },//搜索附加参数
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                columns: [
                    {
                        field: 'sortid',
                        title: '序号',
                        align: 'center',
                        width: '5%'
                    }, {
                        field: 'title',
                        title: '标题',
                        width: '50%'
                    },
                    {
                        field: 'type',
                        title: '类型',
                        align: 'center',
                        width: '10%',
                        formatter: function (value) {
                            var result = "";
                            switch (value) {
                                case 1:
                                    result = "自查条件";
                                    break;
                                case 2:
                                    result = "温馨提醒";
                                    break;
                                case 3:
                                    result = "常见问题解答";
                                    break;
                                default:
                                    result = "未知";
                                    break;
                            }
                            return result;
                        }
                    }, {
                        field: 'status',
                        title: '状态',
                        width: '10%',
                        align: 'center',
                        formatter: function (value) {
                            var result = "";
                            switch (value) {
                                case "N":
                                    result = "<span class=\"label label-danger\">&nbsp;禁用</span>";
                                    break;
                                case "Y":
                                    result = "<span class=\"label label-primary\">&nbsp;启用</span>";
                                    break;
                                default:
                                    break;
                            }
                            return result;
                        }
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        width: '30%',
                        formatter: function operateFormatter(value, row) {
                            var tempCode = "";
                            if (row.status === "Y") {
                                tempCode += '<button type="button" class="status btn btn-default btn-white"><i class="fa fa-toggle-off"></i>&nbsp;禁用&nbsp;</button>';
                            } else {
                                tempCode += '<button type="button" class="status btn btn-default btn-white"><i class="fa fa-toggle-on"></i>&nbsp;启用&nbsp;</button>';
                            }
                            tempCode += '<button type="button" class="update btn btn-white">&nbsp;<i class="fa fa-edit"></i>&nbsp;修改&nbsp;</button>';
                            tempCode += '<button type="button" class="delete btn btn-white">&nbsp;<i class="fa fa-trash"></i>&nbsp;删除&nbsp;</button>';
                            return '<div class="btn-group btn-group-xs">' + tempCode + '</div>';
                        },
                        events: operateEvents
                    }
                ]
            });

            //工具栏 - 新增
            $('.toolbar-save').on('click', function () {
                winModal("新增问题", null);
            });

            /**
             * table公共方法
             */
            //工具栏 - 刷新
            $(".toolbar-refresh").on('click', function () {
                tableRefresh();
            });

            //回显
            function responseHandler(res) {
                return res.rows;
            }


            /**
             * 模态框
             * @param title
             * @param row
             */
            function winModal(title, row) {
                BootstrapDialog.show({
                    type: BootstrapDialog.TYPE_DEFAULT,
                    size: BootstrapDialog.SIZE_WIDE,
                    tabindex: null,//解决select2搜索框失去焦点的问题
                    title: title,
                    closable: true,	//关闭箭头启动
                    closeByBackdrop: false,	//点击空白不消失
                    closeByKeyboard: true,//ESC取消禁用
                    message: $('<div></div>').load('/implementAnswer/save/form.html'),
                    data: {
                        'row': row
                    },
                    buttons: [{
                        label: '取消',
                        cssClass: 'btn-white cancel',
                        icon: 'fa fa-times',
                        action: function (dialog) {
                            dialog.close();
                        }
                    }, {
                        label: '提交' + title,
                        //hotkey: 13,//回车提交
                        cssClass: 'btn-primary',
                        icon: 'fa fa-check',
                        action: function (dialog) {
                            //返回验证结果
                            var flag = $("#winModal").validate().form();
                            if (flag) {
                                $.baseUtils.ajax({
                                    dialog: dialog,
                                    url: '/implementAnswer/save/action',
                                    data: $("#winModal").serialize(),
                                    text: "保存",
                                    isTable: true,
                                    tableName: '#anwserDataList',
                                    isDialog: true
                                })
                            }
                        }
                    }],
                    onshown: function () {
                        $('#serviceId').val(serviceId);
                        console.log(row);
                        if (row != null) {
                            $('#uuid').val(row.uuid);
                            $('#title').val(row.title);
                            $('#type').val(row.type);
                            $('#content').val(row.content);
                            $('#status').val(row.status);
                            $('input[name=status][value=' + row.status + ']').attr('checked', true);
                            $('#sortid').val(row.sortid);
                        }
                    }
                });
            }

        },


    };
});






